// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const calTeamMemberRequest = {
    // calTeam请求的基本url
    BASE_URL : confing.CAL_URL + "/calTeamMember",

    //批量添加班组成员
    adds(userIds,teamId,callback){
        // 拼接URL
        let url = this.BASE_URL + "/adds?t=1";
        if(userIds != undefined){
            userIds.forEach(userId => {
                url += "&userId=" + userId;
            });

            url += "&userId=" + teamId;
            request.get( url,callback);
        }
    },

    //工具栏-批量删除班组成员
    deletes(memberIds,callback){
        // 拼接URL
        let url = this.BASE_URL + "/deletes?t=1";
        if(memberIds != undefined){
            memberIds.forEach(memberId => {
                url += "&memberId=" + memberId;
            });
            request.delete( url,callback);
        }
    },

    // 行编辑-删除当前班组成员
    delete(memberId,callback){
        request.delete(this.BASE_URL + "/" + memberId,callback);
    },

    // 班组成员列表展示 分页
    list(page = 1,limit = 10,calTeamMember,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(calTeamMember){
            if(calTeamMember.memberId){
                url += "&memberId=" + calTeamMember.memberId;
            }
            if(calTeamMember.teamId){
                url += "&teamId=" + calTeamMember.teamId;
            }
            if(calTeamMember.userName){
                url += "&userName=" + calTeamMember.userName;
            }
        }
        // 发送请求
        request.get(url,callbcak);
    }
}

// 将calTeamMemberRequest暴漏出去
export default calTeamMemberRequest;